﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Sector7.Restaurant.CoreType.Enums;
using Sector7.Restaurant.Modules.SYST.Utility;
using Sector7.Restaurant.Modules.SYST.LocalService;
using Sector7.Framework.Enums;
using Sector7.Framework.Utility;
using Sector7.Framework.Core;

namespace Sector7.Restaurant.Modules.SYST.Windows
{
    /// <summary>
    /// AddUnitWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AddUnitWindow: AddModeWindowBase
    {
        public AddUnitWindow()
        {
            InitializeComponent();
        }

        public RS_Unit Unit
        {
            get { return m_entity as RS_Unit; }
            set { m_entity = value; }
        }

        protected override void InitializeForCreating()
        {
            Unit = new RS_Unit();
        }

        protected override void InitializeForUpdating()
        {
            btnContinue.Visibility = Visibility.Hidden;
        }

        /// <summary>
        /// 添加单位信息
        /// </summary>
        /// <returns></returns>
        protected override void AddData()
        {
            switch (m_crud)
            {
                case CrudType.Create:
                    Unit.UnitId = Aide.LocalClient.Invoke<int>(
                        service => service.AddUnit(Unit));
                    break;
                case CrudType.Update:
                    EntityDelta delta = ClientUtil.CreateDelta<EntityDelta>(typeof(RS_Unit));
                    delta.Conditions.Add("UnitId", Unit.UnitId);
                    delta.DeltaProperties.Add("UnitName", Unit.UnitName);

                    Aide.LocalClient.Invoke<int>(
                        service => service.SetUnit(delta));
                    break;
                default:
                    break;
            }

            base.AddData();
        }
    }
}
